﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Nina.Codec;

namespace Nina.Examples.TextLine
{
    class ClientServerExample
    {
        static void Main(string[] args)
        {

            /* Start server */
            NinaSocketAcceptor acceptor = new NinaSocketAcceptor();
            acceptor.SetProtocolHandler(new ServerProtocolHandler());
            acceptor.AddCodecFirst(new DelimiterCodec('\n', Encoding.UTF8));
            acceptor.Bind(7001);
            Console.WriteLine("Server started.");

            /* Sleep briefly to allow the server to start up */
            try
            {
                Thread.Sleep(2000);
            }
            catch { }

            /* Start client */
            NinaSocketConnector connector = new NinaSocketConnector();
            connector.SetProtocolHandler(new ClientProtocolHandler());
            connector.AddCodecFirst(new DelimiterCodec('\n', Encoding.UTF8));
            NinaSession session = connector.Connect(NinaSession.LocalIPAddress, 7001);
        }
    }
}
